package com.lrc.dentalbackend.controller;

import com.lrc.dentalbackend.common.ResponseResult;
import com.lrc.dentalbackend.domain.vo.FriendVO;
import com.lrc.dentalbackend.domain.vo.UserVO;
import com.lrc.dentalbackend.service.FriendService;
import com.lrc.dentalbackend.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/friend")
public class FriendController {
    @Resource
    private FriendService friendService;

    @Resource
    private UserService userService;

    @GetMapping("/search/{username}")
    @ApiOperation("通过姓名模糊查询网友(还未添加好友前海量搜索)")
    public ResponseResult searchFriend(@PathVariable String username){
        return ResponseResult.ok(userService.searchFriend(username));
    }

    @GetMapping("/search/phone/{phone}")
    @ApiOperation("根据手机号查询网友(还未添加好友前海量搜索)")
    public ResponseResult addFriendByPhone(@PathVariable String phone){
        UserVO userVO = userService.searchFriendByPhone(phone);
        return ResponseResult.ok(userVO);
    }

    @PostMapping("/add/{userId}")
    @ApiOperation("根据好友id添加好友")
    public ResponseResult addFriend(@PathVariable Long userId){
        friendService.addFriend(userId);
        return ResponseResult.ok();
    }

    @GetMapping("/list")
    @ApiOperation("获取好友列表")
    public ResponseResult listFriend(){
        List<FriendVO> friendList = friendService.listByUserId();
        return ResponseResult.ok(friendList);
    }

    @PostMapping("/delete/{friendId}")
    @ApiOperation("删除好友")
    public ResponseResult deleteFriend(@PathVariable Long friendId){
        friendService.deleteFriend(friendId);
        return ResponseResult.ok();
    }

    @GetMapping("/search/friends")
    @ApiOperation("根据用户名模糊搜索好友")
    public ResponseResult searchFriendsByUsername(@RequestParam String username){
        List<FriendVO> friendVOList = friendService.searchFriendsByUsername(username);
        return ResponseResult.ok(friendVOList);
    }


}
